package com.gsj.lx.mybatislx.controller;

import com.gsj.lx.mybatislx.dao.UserService;
import com.gsj.lx.mybatislx.mapper.UserMapper;
import com.gsj.lx.mybatislx.model.User;
import com.gsj.lx.mybatislx.model.UserSexEnum;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @program: mybatislx
 * @description:
 * @author: 郭书江
 * @create: 2022-05-20 10:15
 **/
@Slf4j
@RestController
@RequestMapping("user")
@Api(tags = "user接口")
public class UserController {

    @Autowired
    UserMapper userMapper;
    @Autowired
    UserService userService;

    @PostMapping(value = "/insert")
    @ApiOperation("添加用户")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "user",value = "用户",required = true)
    })
    public void  insert(@RequestBody User user){
        int i = userMapper.insert(user);
        log.info("插入"+i);
    }
    @PostMapping(value = "/insert1")
    public void  insert1(){
        User user = new User("11", "@2", "man");
        int i = userMapper.insert(user);
        log.info("插入"+i);
    }
    @GetMapping(value = "/get")
    public List<User>  get(){

        List<User> all = userMapper.getAll();
        log.info("查询"+all);
        return all;
    }
    @PostMapping(value = "/getOne/{id}")
    public User  getOne( @PathVariable(value = "id",required = false) Long id,@RequestParam (value = "username") String username){
        User all = userService.getUserOne(id,username);
        log.info("查询"+all);
        return all;
    }
}
